package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.expetion.NotNullException;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import com.itheima.utnil.GlbalExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private EmpMapper empMapper;


    @Override
    public Integer add(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());

        // 手动设置 clazzId，假设有一个默认值或从其他地方获取
        if (student.getClazzId() == null) {
            student.setClazzId(1); // 替换为你实际获取 clazzId 的方式
        }

        return studentMapper.insert(student);


    }


    @Override
    public PageResult page(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());
        List<Emp> emplist = studentMapper.list(studentQueryParam);
        Page<Emp> p = (Page<Emp>) emplist;

        return new PageResult(p.getTotal(),p.getResult());

    }
//删除
    @Override
    public void delete(List<Integer> ids) {



         studentMapper.delete(ids);

    }
// 回显
    @Override
    public Student getInto(Integer id) {
        return studentMapper.getById(id);
    }
//修改
    @Override
    public void update(Student stu) {
        stu.setUpdateTime(LocalDateTime.now());
        studentMapper.updateById(stu);
    }
//违纪
    @Override
    public void updateViolation(Integer id, Short score) {
        studentMapper.updateViolation(id,score);
    }

}
